<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionView::Helpers::NumberHelper</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionView::Helpers::NumberHelper</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/actionpack/lib/action_view/helpers/number_helper_rb.html">
                vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Provides methods for converting numbers into formatted strings. Methods are
provided for phone numbers, currency, percentage, precision, positional
notation, and file size.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000995">number_to_currency</a>&nbsp;&nbsp;
      <a href="#M000999">number_to_human_size</a>&nbsp;&nbsp;
      <a href="#M000996">number_to_percentage</a>&nbsp;&nbsp;
      <a href="#M000994">number_to_phone</a>&nbsp;&nbsp;
      <a href="#M000997">number_with_delimiter</a>&nbsp;&nbsp;
      <a href="#M000998">number_with_precision</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000995" class="method-detail">
        <a name="M000995"></a>

        <div class="method-heading">
          <a href="#M000995" class="method-signature">
          <span class="method-name">number_to_currency</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> into a currency string (e.g., $13.65). You can
customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 2).

</li>
<li><tt>:unit</tt> - Sets the denomination of the currency (defaults to
&quot;$&quot;).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
<li><tt>:delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;,&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_currency(1234567890.50)                    # =&gt; $1,234,567,890.50
 number_to_currency(1234567890.506)                   # =&gt; $1,234,567,890.51
 number_to_currency(1234567890.506, :precision =&gt; 3)  # =&gt; $1,234,567,890.506

 number_to_currency(1234567890.50, :unit =&gt; &quot;&amp;pound;&quot;, :separator =&gt; &quot;,&quot;, :delimiter =&gt; &quot;&quot;)
 # =&gt; &amp;pound;1234567890,50
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000995-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000995-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 65</span>
65:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_to_currency</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">options</span> = {})
66:         <span class="ruby-identifier">options</span>   = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">stringify_keys</span>
67:         <span class="ruby-identifier">precision</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;precision&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value">2</span>
68:         <span class="ruby-identifier">unit</span>      = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;unit&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;$&quot;</span>
69:         <span class="ruby-identifier">separator</span> = <span class="ruby-identifier">precision</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;separator&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;.&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;&quot;</span>
70:         <span class="ruby-identifier">delimiter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;delimiter&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;,&quot;</span>
71: 
72:         <span class="ruby-keyword kw">begin</span>
73:           <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">number_with_precision</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">precision</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>)
74:           <span class="ruby-identifier">unit</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">number_with_delimiter</span>(<span class="ruby-identifier">parts</span>[<span class="ruby-value">0</span>], <span class="ruby-identifier">delimiter</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">separator</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">parts</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_s</span>
75:         <span class="ruby-keyword kw">rescue</span>
76:           <span class="ruby-identifier">number</span>
77:         <span class="ruby-keyword kw">end</span>
78:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000999" class="method-detail">
        <a name="M000999"></a>

        <div class="method-heading">
          <a href="#M000999" class="method-signature">
          <span class="method-name">number_to_human_size</span><span class="method-args">(size, precision=1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats the bytes in <tt>size</tt> into a more understandable
representation (e.g., giving it 1500 yields 1.5 KB). This method is useful
for reporting file sizes to users. This method returns nil if <tt>size</tt>
cannot be converted into a number. You can change the default precision of
1 using the precision parameter <tt>precision</tt>.
</p>
<h4>Examples</h4>
<pre>
 number_to_human_size(123)           # =&gt; 123 Bytes
 number_to_human_size(1234)          # =&gt; 1.2 KB
 number_to_human_size(12345)         # =&gt; 12.1 KB
 number_to_human_size(1234567)       # =&gt; 1.2 MB
 number_to_human_size(1234567890)    # =&gt; 1.1 GB
 number_to_human_size(1234567890123) # =&gt; 1.1 TB
 number_to_human_size(1234567, 2)    # =&gt; 1.18 MB
 number_to_human_size(483989, 0)     # =&gt; 4 MB
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000999-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000999-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 164</span>
164:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_to_human_size</span>(<span class="ruby-identifier">size</span>, <span class="ruby-identifier">precision</span>=<span class="ruby-value">1</span>)
165:         <span class="ruby-identifier">size</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-constant">Float</span>(<span class="ruby-identifier">size</span>)
166:         <span class="ruby-keyword kw">case</span>
167:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">size</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>;    <span class="ruby-value str">&quot;1 Byte&quot;</span>
168:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">kilobyte</span>; <span class="ruby-value str">&quot;%d Bytes&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">size</span>
169:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">megabyte</span>; <span class="ruby-node">&quot;%.#{precision}f KB&quot;</span>  <span class="ruby-operator">%</span> (<span class="ruby-identifier">size</span> <span class="ruby-operator">/</span> <span class="ruby-value">1.0</span>.<span class="ruby-identifier">kilobyte</span>)
170:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">gigabyte</span>; <span class="ruby-node">&quot;%.#{precision}f MB&quot;</span>  <span class="ruby-operator">%</span> (<span class="ruby-identifier">size</span> <span class="ruby-operator">/</span> <span class="ruby-value">1.0</span>.<span class="ruby-identifier">megabyte</span>)
171:           <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">size</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">terabyte</span>; <span class="ruby-node">&quot;%.#{precision}f GB&quot;</span>  <span class="ruby-operator">%</span> (<span class="ruby-identifier">size</span> <span class="ruby-operator">/</span> <span class="ruby-value">1.0</span>.<span class="ruby-identifier">gigabyte</span>)
172:           <span class="ruby-keyword kw">else</span>                    <span class="ruby-node">&quot;%.#{precision}f TB&quot;</span>  <span class="ruby-operator">%</span> (<span class="ruby-identifier">size</span> <span class="ruby-operator">/</span> <span class="ruby-value">1.0</span>.<span class="ruby-identifier">terabyte</span>)
173:         <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/([0-9])\.?0+ /</span>, <span class="ruby-value str">'\1 '</span> )
174:       <span class="ruby-keyword kw">rescue</span>
175:         <span class="ruby-keyword kw">nil</span>
176:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000996" class="method-detail">
        <a name="M000996"></a>

        <div class="method-heading">
          <a href="#M000996" class="method-signature">
          <span class="method-name">number_to_percentage</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> as a percentage string (e.g., 65%). You can
customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:precision</tt> - Sets the level of precision (defaults to 3).

</li>
<li><tt>:separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_percentage(100)                         # =&gt; 100.000%
 number_to_percentage(100, :precision =&gt; 0)        # =&gt; 100%

 number_to_percentage(302.24398923423, :precision =&gt; 5)
 # =&gt; 302.24399%
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000996-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000996-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 93</span>
 93:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_to_percentage</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">options</span> = {})
 94:         <span class="ruby-identifier">options</span>   = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">stringify_keys</span>
 95:         <span class="ruby-identifier">precision</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;precision&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value">3</span>
 96:         <span class="ruby-identifier">separator</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;separator&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;.&quot;</span>
 97: 
 98:         <span class="ruby-keyword kw">begin</span>
 99:           <span class="ruby-identifier">number</span> = <span class="ruby-identifier">number_with_precision</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">precision</span>)
100:           <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">number</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>)
101:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">at</span>(<span class="ruby-value">1</span>).<span class="ruby-identifier">nil?</span>
102:             <span class="ruby-identifier">parts</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;%&quot;</span>
103:           <span class="ruby-keyword kw">else</span>
104:             <span class="ruby-identifier">parts</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">separator</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">parts</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;%&quot;</span>
105:           <span class="ruby-keyword kw">end</span>
106:         <span class="ruby-keyword kw">rescue</span>
107:           <span class="ruby-identifier">number</span>
108:         <span class="ruby-keyword kw">end</span>
109:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000994" class="method-detail">
        <a name="M000994"></a>

        <div class="method-heading">
          <a href="#M000994" class="method-signature">
          <span class="method-name">number_to_phone</span><span class="method-args">(number, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> into a US phone number (e.g., (555) 123-9876).
You can customize the format in the <tt>options</tt> hash.
</p>
<h4>Options</h4>
<ul>
<li><tt>:area_code</tt> - Adds parentheses around the area code.

</li>
<li><tt>:delimiter</tt> - Specifies the delimiter to use (defaults to
&quot;-&quot;).

</li>
<li><tt>:extension</tt> - Specifies an extension to add to the end of the
generated number.

</li>
<li><tt>:country_code</tt> - Sets the country code for the phone number.

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_to_phone(1235551234)                                        # =&gt; 123-555-1234
 number_to_phone(1235551234, :area_code =&gt; true)                    # =&gt; (123) 555-1234
 number_to_phone(1235551234, :delimiter =&gt; &quot; &quot;)                     # =&gt; 123 555 1234
 number_to_phone(1235551234, :area_code =&gt; true, :extension =&gt; 555) # =&gt; (123) 555-1234 x 555
 number_to_phone(1235551234, :country_code =&gt; 1)                    # =&gt; +1-123-555-1234

 number_to_phone(1235551234, :country_code =&gt; 1, :extension =&gt; 1343, :delimiter =&gt; &quot;.&quot;)
 =&gt; +1.123.555.1234 x 1343
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000994-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000994-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 26</span>
26:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_to_phone</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">options</span> = {})
27:         <span class="ruby-identifier">number</span>       = <span class="ruby-identifier">number</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">number</span>.<span class="ruby-identifier">nil?</span>
28:         <span class="ruby-identifier">options</span>      = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">stringify_keys</span>
29:         <span class="ruby-identifier">area_code</span>    = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;area_code&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
30:         <span class="ruby-identifier">delimiter</span>    = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;delimiter&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">&quot;-&quot;</span>
31:         <span class="ruby-identifier">extension</span>    = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;extension&quot;</span>].<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">strip</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
32:         <span class="ruby-identifier">country_code</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;country_code&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
33: 
34:         <span class="ruby-keyword kw">begin</span>
35:           <span class="ruby-identifier">str</span> = <span class="ruby-value str">&quot;&quot;</span>
36:           <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;+#{country_code}#{delimiter}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">country_code</span>.<span class="ruby-identifier">blank?</span>
37:           <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">area_code</span>
38:             <span class="ruby-identifier">number</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/([0-9]{1,3})([0-9]{3})([0-9]{4}$)/</span>,<span class="ruby-node">&quot;(\\1) \\2#{delimiter}\\3&quot;</span>)
39:           <span class="ruby-keyword kw">else</span>
40:             <span class="ruby-identifier">number</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/([0-9]{1,3})([0-9]{3})([0-9]{4})$/</span>,<span class="ruby-node">&quot;\\1#{delimiter}\\2#{delimiter}\\3&quot;</span>)
41:           <span class="ruby-keyword kw">end</span>
42:           <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot; x #{extension}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">extension</span>.<span class="ruby-identifier">blank?</span>
43:           <span class="ruby-identifier">str</span>
44:         <span class="ruby-keyword kw">rescue</span>
45:           <span class="ruby-identifier">number</span>
46:         <span class="ruby-keyword kw">end</span>
47:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000997" class="method-detail">
        <a name="M000997"></a>

        <div class="method-heading">
          <a href="#M000997" class="method-signature">
          <span class="method-name">number_with_delimiter</span><span class="method-args">(number, delimiter=&quot;,&quot;, separator=&quot;.&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> with grouped thousands using <tt>delimiter</tt>
(e.g., 12,324). You can customize the format using optional
<em>delimiter</em> and <em>separator</em> parameters.
</p>
<h4>Options</h4>
<ul>
<li><tt>delimiter</tt> - Sets the thousands delimiter (defaults to
&quot;,&quot;).

</li>
<li><tt>separator</tt> - Sets the separator between the units (defaults to
&quot;.&quot;).

</li>
</ul>
<h4>Examples</h4>
<pre>
 number_with_delimiter(12345678)       # =&gt; 12,345,678
 number_with_delimiter(12345678.05)    # =&gt; 12,345,678.05
 number_with_delimiter(12345678, &quot;.&quot;)  # =&gt; 12.345.678

 number_with_delimiter(98765432.98, &quot; &quot;, &quot;,&quot;)
 # =&gt; 98 765 432,98
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000997-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000997-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 125</span>
125:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_with_delimiter</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">delimiter</span>=<span class="ruby-value str">&quot;,&quot;</span>, <span class="ruby-identifier">separator</span>=<span class="ruby-value str">&quot;.&quot;</span>)
126:         <span class="ruby-keyword kw">begin</span>
127:           <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">number</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">'.'</span>)
128:           <span class="ruby-identifier">parts</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/(\d)(?=(\d\d\d)+(?!\d))/</span>, <span class="ruby-node">&quot;\\1#{delimiter}&quot;</span>)
129:           <span class="ruby-identifier">parts</span>.<span class="ruby-identifier">join</span> <span class="ruby-identifier">separator</span>
130:         <span class="ruby-keyword kw">rescue</span>
131:           <span class="ruby-identifier">number</span>
132:         <span class="ruby-keyword kw">end</span>
133:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000998" class="method-detail">
        <a name="M000998"></a>

        <div class="method-heading">
          <a href="#M000998" class="method-signature">
          <span class="method-name">number_with_precision</span><span class="method-args">(number, precision=3)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Formats a <tt>number</tt> with the specified level of <tt>precision</tt>
(e.g., 112.32 has a precision of 2). The default level of precision is 3.
</p>
<h4>Examples</h4>
<pre>
 number_with_precision(111.2345)     # =&gt; 111.235
 number_with_precision(111.2345, 2)  # =&gt; 111.24
 number_with_precision(13, 5)        # =&gt; 13.00000
 number_with_precision(389.32314, 0) # =&gt; 389
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000998-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000998-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/actionpack/lib/action_view/helpers/number_helper.rb, line 143</span>
143:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">number_with_precision</span>(<span class="ruby-identifier">number</span>, <span class="ruby-identifier">precision</span>=<span class="ruby-value">3</span>)
144:         <span class="ruby-node">&quot;%01.#{precision}f&quot;</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">number</span>
145:       <span class="ruby-keyword kw">rescue</span>
146:         <span class="ruby-identifier">number</span>
147:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>